<?php
/**
 * Created by PhpStorm.
 * User: fangwei
 * Date: 2019-08-20
 * Time: 16:26
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\ICategory;
use App\Http\Requests\Admin\CategoryInputDTO;
use App\Util\LayUiVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class CategoryController extends Controller
{
    protected $categoryService;
    public function __construct(ICategory $categoryService)
    {
        $this->categoryService = $categoryService;
    }

    public function page(Request $request) {
        $search = [];
        if ($request->get('title')) {
            $search['title'] = $request->get('title');
        }

        $dao = $this->categoryService->lists($search, $request->get('page', 1), $request->get('limit','10'));
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.success')]));
    }

    public function show($id) {
        $dao = $this->categoryService->byId($id);
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.success')]));
    }

    public function store(CategoryInputDTO $clientVisitDTO){
        $this->categoryService->store($clientVisitDTO);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function update(CategoryInputDTO $clientVisitDTO,$id){
        $this->categoryService->update($clientVisitDTO,$id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function delete($id){
        $this->categoryService->delete($id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }
}